<?php
namespace Act\Os\Ajax;
use Lib\Action;
class GetRegion extends Action{
	public function doGet(){
		$fid = get('fid','','trim,htmlspecialchars');
		$type = get('type','','trim');
		$this->checkParam($type);
		$this->checkParam($fid);
		$child_types = ['province'=>'city','city'=>'district'];
		if(!in_array($type, array_keys($child_types))){
			echo '';
			return;
		}
		$child_type = $child_types[$type];
		if(empty($child_type)){
			echo '';
			return ;
		}
		$u_type = ucwords($child_type);
		$mod = model('#'.$u_type);
		$method = 'get'.$u_type.'ByFather';
		$result = $mod->$method($fid);
		$str = '';
		if($result){
			$str = '<select name="'.$child_type.'" id="'.$child_type.'" style="width:150px;margin-right:5px">';
			$str .= '<option value="0">请选择</option>';

			foreach($result as $item){
				$str .= "<option value=\"{$item['sn']}\">{$item['name']}</option>";
			}
			$str .= '</select>';
		}
		echo $str;
	}
}